package com.fyyg.wechat.util.userdefinedtag;

import java.io.IOException;


import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

import org.apache.commons.lang3.StringUtils;

/**
 * 字符串匿名处理
 * @author VTKD
 *
 */
public class AnonymousTag extends TagSupport {

	private static final long serialVersionUID = 1L;
	private int beignIndex=1;
	private int endIndex=1;
	private String parttern="*";
	private String value;
	private boolean if_all_star=false;  //true 表款 beignIndex之后全部使用parttern替代

	public String getParttern() {
		return parttern;
	}

	public void setParttern(String parttern) {
		this.parttern = parttern;
	}

	public int doStartTag() throws JspException {
		
		StringBuilder content=new StringBuilder("");  
		if(! StringUtils.isBlank(value)){
			int length=value.length();
			if(length==11){
				content.append(value.substring(0,3));
				for(int i=0;i<4;i++){
					content.append(parttern);
				}
				content.append(value.substring(7,length));
			}else{
				content.append(value);
			}
		}
		try {
			pageContext.getOut().write(content.toString());
		} catch (IOException e) {
			e.printStackTrace();
		}
		return super.doStartTag();
	}

	public void setBeignIndex(int beignIndex) {
		this.beignIndex = beignIndex;
	}

	public void setEndIndex(int endIndex) {
		this.endIndex = endIndex;
	}

	public void setValue(String value) {
		this.value = value;
	}

	public boolean isIf_all_star() {
		return if_all_star;
	}

	public void setIf_all_star(boolean if_all_star) {
		this.if_all_star = if_all_star;
	}
	
}
